bargraph2 2.2.1
bargraph2.h
Go to the documentation of this file.
1/****************************************************************************
2** Copyright (C) 2026 MikroElektronika d.o.o.
3** Contact: https://www.mikroe.com/contact
4**
5** Permission is hereby granted, free of charge, to any person obtaining a copy
6** of this software and associated documentation files (the "Software"), to deal
7** in the Software without restriction, including without limitation the rights
8** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9** copies of the Software, and to permit persons to whom the Software is
10** furnished to do so, subject to the following conditions:
11** The above copyright notice and this permission notice shall be
12** included in all copies or substantial portions of the Software.
13**
14** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20** USE OR OTHER DEALINGS IN THE SOFTWARE.
21****************************************************************************/
22
31// ----------------------------------------------------------------------------
32
33#ifndef BARGRAPH2_H
34#define BARGRAPH2_H
35
40#ifdef PREINIT_SUPPORTED
41#include "preinit.h"
42#endif
43
44#ifdef MikroCCoreVersion
45 #if MikroCCoreVersion >= 1
46 #include "delays.h"
47 #endif
48#endif
49
50#include "drv_digital_out.h"
51#include "drv_digital_in.h"
52#include "drv_spi_master.h"
53
54// -------------------------------------------------------------- PUBLIC MACROS
59
64
65#define BARGRAPH2_MAP_MIKROBUS( cfg, mikrobus ) \
66 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
67 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
68 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
69 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
70 cfg.mr = MIKROBUS( mikrobus, MIKROBUS_RST ); \
71 cfg.pwm = MIKROBUS( mikrobus, MIKROBUS_PWM )
72
73
78#define BARGRAPH2_RETVAL uint8_t
79
80#define BARGRAPH2_OK 0x00
81#define BARGRAPH2_INIT_ERROR 0xFF
83
88#define BARGRAPH2_POWER_ON 1
89#define BARGRAPH2_POWER_OFF 0
91
96#define BARGRAPH2_LED_SEG_0 0x00
97#define BARGRAPH2_LED_SEG_1 0x01
98#define BARGRAPH2_LED_SEG_2 0x02
99#define BARGRAPH2_LED_SEG_3 0x04
100#define BARGRAPH2_LED_SEG_4 0x08
101#define BARGRAPH2_LED_SEG_5 0x10
102#define BARGRAPH2_LED_SEG_6 0x20
103#define BARGRAPH2_LED_SEG_7 0x40
104#define BARGRAPH2_LED_SEG_8 0x80
106 // End group macro
108// --------------------------------------------------------------- PUBLIC TYPES
113
117typedef struct
118{
119 digital_out_t cs;
120
121 // Output pins
122
123 digital_out_t mr;
124 digital_out_t pwm;
125
126 // Modules
127
128 spi_master_t spi;
129 pin_name_t chip_select;
130
132
136typedef struct
137{
138 // Communication gpio pins
139
140 pin_name_t miso;
141 pin_name_t mosi;
142 pin_name_t sck;
143 pin_name_t cs;
144
145 // Additional gpio pins
146
147 pin_name_t mr;
148 pin_name_t pwm;
149
150 // static variable
151
152 uint32_t spi_speed;
153 spi_master_mode_t spi_mode;
154 spi_master_chip_select_polarity_t cs_polarity;
155
157 // End types group
159// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
160
165#ifdef __cplusplus
166extern "C"{
167#endif
168
178
188
197
209void bargraph2_generic_transfer ( bargraph2_t *ctx, uint8_t *wr_buf, uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len );
210
219
228void bargraph2_write_byte ( bargraph2_t *ctx, uint8_t input_data );
229
241void bargraph2_led_green ( bargraph2_t *ctx, uint8_t index );
242
254void bargraph2_led_red ( bargraph2_t *ctx, uint8_t index );
255
267void bargraph2_led_yellow ( bargraph2_t *ctx, uint8_t index );
268
279void bargraph2_leds_green ( bargraph2_t *ctx, int start_index, int end_index );
280
291void bargraph2_leds_red ( bargraph2_t *ctx, int start_index, int end_index );
292
303void bargraph2_leds_yellow ( bargraph2_t *ctx, int start_index, int end_index );
304
313
322void barpgraph2_power ( bargraph2_t *ctx, uint8_t power_on_off );
323
324#ifdef __cplusplus
325}
326#endif
327#endif // _BARGRAPH2_H_
328 // End public_function group
331
332// ------------------------------------------------------------------------- END
#define BARGRAPH2_RETVAL
Definition bargraph2.h:78
void bargraph2_lights_out(bargraph2_t *ctx)
Lights out function.
BARGRAPH2_RETVAL bargraph2_init(bargraph2_t *ctx, bargraph2_cfg_t *cfg)
Initialization function.
void bargraph2_default_cfg(bargraph2_t *ctx)
Click Default Configuration function.
void bargraph2_leds_yellow(bargraph2_t *ctx, int start_index, int end_index)
LEDs red function.
void bargraph2_cfg_setup(bargraph2_cfg_t *cfg)
Config Object Initialization function.
void bargraph2_generic_transfer(bargraph2_t *ctx, uint8_t *wr_buf, uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len)
Generic transfer function.
void bargraph2_led_red(bargraph2_t *ctx, uint8_t index)
LED red function.
void barpgraph2_power(bargraph2_t *ctx, uint8_t power_on_off)
Lights out function.
void bargraph2_reset(bargraph2_t *ctx)
Reset function.
void bargraph2_led_green(bargraph2_t *ctx, uint8_t index)
LED green function.
void bargraph2_leds_red(bargraph2_t *ctx, int start_index, int end_index)
LEDs red function.
void bargraph2_leds_green(bargraph2_t *ctx, int start_index, int end_index)
LEDs green function.
void bargraph2_write_byte(bargraph2_t *ctx, uint8_t input_data)
Write byte function.
void bargraph2_led_yellow(bargraph2_t *ctx, uint8_t index)
LED yellow function.
Click configuration structure definition.
Definition bargraph2.h:137
spi_master_chip_select_polarity_t cs_polarity
Definition bargraph2.h:154
pin_name_t mr
Definition bargraph2.h:147
pin_name_t sck
Definition bargraph2.h:142
spi_master_mode_t spi_mode
Definition bargraph2.h:153
pin_name_t mosi
Definition bargraph2.h:141
uint32_t spi_speed
Definition bargraph2.h:152
pin_name_t pwm
Definition bargraph2.h:148
pin_name_t miso
Definition bargraph2.h:140
pin_name_t cs
Definition bargraph2.h:143
Click ctx object definition.
Definition bargraph2.h:118
digital_out_t cs
Definition bargraph2.h:119
spi_master_t spi
Definition bargraph2.h:128
digital_out_t pwm
Definition bargraph2.h:124
digital_out_t mr
Definition bargraph2.h:123
pin_name_t chip_select
Definition bargraph2.h:129